<?php
namespace Home\Controller;
use Think\Controller;
class GoodsController extends CommonController {

    /**
     * 商品列表
     *
     * @return void
     * @author
     **/
    function lists()
    {

        // $count=$this->Model->relation(true)->count();//查询满足要求的总记录数
        // $Page=new \Think\Page($count,15);//实例化分页类,传入总记录数和每页显示的记录数(1)
        // $Page->setConfig('prev','上一页');//上一页
        // $Page->setConfig('last','尾页');//尾页
        // $show=$Page->show();// 输出分页显示
        // $list = $this->Model->relation(true)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();


        //调用在后台模型层封装的查询
        $data=D('Admin/goods')->getSelect();

        $this->assign('list',$data['list']);// 赋值数据集
        $this->assign('page',$data['page']);// 赋值分页输出
        $this->display(); // 输出模板
    }

    /**
     * 商品详情页
     *
     * @return void
     * @author
     **/
    function detail()
    {
         // $goods_id=I('get.id');
         // $goods=$this->Model->where("id=$goods_id")->select();
         // $this->assign('goods',$goods);

        $goods_id=I('get.id');

        //查商品数据表
        $goods=D('Admin/goods')->relation('goods_img')->getById($goods_id);
        //查询规格数据表
        $type_id=$goods['goods_type_id'];
        $spec=D('Admin/spec')->where("goods_type_id=$type_id")->relation(true)->order('id asc')->select();

        // print_r($spec);die;
        $this->assign('goods',$goods);
        $this->assign('spec',$spec);
        $this->display();
    }

}